package com.example.springbootdatajpa.controller;

import com.example.springbootdatajpa.entities.Product;
import com.example.springbootdatajpa.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping(value = "/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping(value = "/findAllBetweenMinAndMax",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<List<Product>> findAllBetweenMinAndMax(@RequestParam("min") final BigDecimal min,
                                                                 @RequestParam("max") final BigDecimal max){
        List<Product> products = productService.findAllBetweenStoreProcedure(min,max);
        return new ResponseEntity<>(products, HttpStatus.OK);
    }
}
